import math
def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n > 2 and n % 2 == 0:
        return False
    max_divisor = math.floor(math.sqrt(n))
    for d in range(3, 1 + max_divisor, 2):
        if n % d == 0:
            return False
    return True
def find_closest_prime(input_str):
    words_to_num = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
    nums = input_str.split()
    if len(nums) != 3:
        print("Wrong input")
        exit()
    for i in nums:
        if i not in words_to_num:
            print("Wrong input")
            exit()
    nums = [words_to_num[num] for num in nums]
    num = int(''.join(nums))
    if 100 <= num <= 999:
        i = 0
        while True:
            if is_prime(num - i) or is_prime(num + i):
                if is_prime(num - i) and is_prime(num + i):
                    print(f"{num - i} {num + i}")
                elif is_prime(num - i):
                    print(num - i)
                else:
                    print(num + i)
                break
            i += 1
    else:
        print("Wrong input")
input_str = input()
find_closest_prime(input_str)